<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String basepath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath() + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link rel="stylesheet" href="css/admin_add.css" />
<div class="body_top">
	<div>
		<p>管理导师</p>
		<div>
			<p>INTRODUUCTION OF A MENTOR</p>
			<p class="last_p">ENTERPRENEURSHIP NETWORK TO CREATE INFINITE
				POSSIBILITY</p>
		</div>
	</div>
</div>
<div id="teac_all">
<div class="fenlei">
	<ul>
		<li>是否已经指导团队：</li>
		<li class="leixing" title="1">是</li>
		<li class="leixing" title="0">否</li>
	</ul>
</div>
<form action="admin/addTeac" method="post">
<div class="add_teacbox clearfix" >
	<div>
		<p><b>*姓名</b><input type="text" name="name"><span></span></p>
		<p><b>*教师编号</b><input type="text" name="no"><span></span></p>
		<p><b>*邮箱</b><input type="email" name="loname"><span></span></p>
		<p><b>*电话</b><input type="text" name="tel"><span></span></p>
		<p><b>*分配</b>
		<select name="type">
			<option value ="0">不分配</option>
			<option value ="1">校内</option>
			<option value ="2">校外</option>
		</select><span></span></p>
	</div>
	<div><textarea placeholder="请输入导师的简介" name="explain"></textarea></div>
	<div>
		<input type="submit" value="添加">
		<input id="cancel_teac" type="button" value="取消" > 			
	</div>
</div>
</form>
<div class="ds clearfix yjds">
    <div id="div_detail">
        <span id="close_div"></span>
        <div id="detail_content">
        <p>ID:</p><p>辅导团队ID：</p><p>姓名：</p><p>邮箱：</p><p>电话：</p><p>登录名：</p><p>教师编号：</p><p>简介：</p>
        </div>
    </div>
	<div class="tjds">
		<img src="img/tjds.png"><span>添加导师</span>
	</div>
	<div id="each_teac">
		<c:forEach items="${requestScope.tutors }" var="tutor">
			<div>
				<div class="ds_left">
					<img
						src="${tutor.get(0).tu_logo != null ? tutor.get(0).tu_logo : 'img/tutor3.png'}">
				</div>
				<div class="ds_right">

					<span class="remove">一</span>

					<p>ID:<span id="div_teacid" >${tutor.get(0).tu_id}</span></p>
					<p>姓名:<span>${tutor.get(0).tu_name}</span></p>
					<p>帐号:<span>${tutor.get(0).tu_ctime}410596154@qq.com</span></p>
					<p>电话:<span>${tutor.get(0).tu_ctime}</span></p>
					<p>辅导方向:<span>${tutor.get(1).gd_name}</span></p>
				</div>
				<div class="ds_bottom">
					<button>查看更多</button>
				</div>
			</div>
		</c:forEach>
	</div>
</div>
</div>
<div class="fy" title="${sum != null?sum:1 }">
	<span id="pre_page">上一页</span>
		<ul>
		</ul>
	<span id="next_page">下一页</span>
</div>
<script type="text/javascript">
$(document).ready(function(){
	//类型选择
	var kind="teac";
	var type="";
	/*  var sum =$("div.fy").attr("title"); */
	var sum = 20;
	var connect_page=0;
	printList(1);
	$("li.leixing").click(function(){
		$(this).attr("id","bg_black");
		$(this).siblings().attr("id","");
		connect_data(kind,1,$(this).attr("title"));
	})
	//添加导师信息的弹出框
	$(".tjds").click(function(){
			$("div.add_teacbox").slideToggle();
		});
	$("#cancel_teac").click(function(){
		$("div.add_teacbox").slideUp();
	})

	
	//删除数据导师
	
		$("#each_teac").delegate('.remove','click',function(){
            if(confirm("确定删除?")){
                //取得被删投资人的id值
                var tea_id = $(this).next().children('span').text();
                var that= $(this);
                //返回数据
                var obj_id={
                    type:"teac",
                    id:tea_id   
                };
                console.log(obj_id);
                 getData("admin/del",delete_teac,obj_id,that); 
                
            }
        })
		
		//删除导师页面响应
		function delete_teac(data,that){
		if(data){
			that.parent().parent().css("display","none");
		}else{
			alert("删除失败，请重试！");
		}
	}
		//查看导师详细信息
		$("#each_teac").delegate('button','click',function(){
			var teac_id =$(this).parent().prev().children().eq(1).children().text();
			var that =$(this);
            var address="admin/seekInfo?type=teac&&id="+teac_id;
			 getData(address,see_teac); 
		})

        //导师详情的回调函数 
		function see_teac(data){
            $("#div_detail").slideDown(400);
            $(".back_shadow").css("display","block");
            var that=data.tutor[0].list;
            $("#detail_content").html("<p><b>ID：</b>"+that[0].tu_id+"</p><p><b>团队ID：</b></p><p><b>姓名：</b>"+that[0].tu_name+"</p><p><b>邮箱：</b>"+that[0].tu_loname+"</p><p><b>电话：</b>"+that[0].tel+"</p><p><b>登录名：</b>"+that[0].tu_loname+"</p><p><b>辅导方向：</b>"+that[1].gd_name+"</p><p><b>教师编号：</b></p><p><b>简介：</b>"+that[0].tu_explain+"</p>")
			
		}
        $("#close_div,.back_shadow").click(function(){
            $("#div_detail").slideUp(400);
            $(".back_shadow").css("display","none");
        })


// 分页及动态写数据	  admin/fenye?html=teac&&type=?&&page=?

	 
   function printList(index){
     var fy_html="";
     var show = sum-index>7?8:sum-index+1;
     if(index<=connect_page){
         for(var i=8;i>0;i--){
             fy_html+="<li>"+(index-i+1)+"</li>";
         }
         $(".fy>ul").html(fy_html);
         $(".fy>ul>li").eq(7).addClass('fy_on');
     }else{
         for(var i=0;i<show;i++){
             fy_html+="<li>"+(index+i)+"</li>";
         }
         $(".fy>ul").html(fy_html);
         $(".fy>ul>li").eq(0).addClass('fy_on');
     }
     connect_page=index;
 }
	    //点击分页  分别触发ajax事件以及分页列表事件
	    $(".fy>ul").delegate('li','click',function(){
	        type=$("#bg_black").attr("title");
	        $(this).addClass('fy_on');
	        $(this).siblings("li").attr("class","");
	        var page = $(this).html();
	        if(sum>8&&(page%7==1)&&page>7){
	            printList(Number(page));
	            }else{
	                connect_page=page;
	            }
	            connect_data(kind,page,type);
	            
	        })
	$("#pre_page").click(function(){
     var pre_page=(connect_page-1)%7;
     pre_page= pre_page==0?7:pre_page;
     $("div.fy>ul>li").eq(pre_page-1).trigger("click");
 });
 
  $("#next_page").click(function(){
     var next_page=(Number(connect_page)+1)%7;
      next_page= next_page==0?7:next_page ;
      next_page= next_page==1?8:next_page ;
     $("div.fy>ul>li").eq(next_page-1).trigger("click");
 }) 
 
	
 // 上一页  and 下一页

 function connect_data(kind,page,type){
     type= (type == undefined?"":"&&type="+type);
     var address ="admin/fenye?html="+kind+type+"&&page="+page;
     getData(address,printNews)
 }
 // ajax传值取相应数据
 function getData(address,callback,Data,that){
     $.ajax({
         type:"post",
         url:address,
         data:Data,
         dataType:"json",
         success:function(data){
             callback(data,that);
         },
         error:function(e){
             console.log(e.message);
         }
     });
 }
	        
	//回调函数渲染页面
	function printNews(data){
		var teac_html="";
		$.each(data.paging,function(){
			var that=this.list;
			teac_html+= "<div class='ds'><div class='ds_left'><img src='img/tutor1.png'/></div><div class='ds_right'><span class='remove'>一</span><p>ID:<span>"+that[0].tu_id+"</span></p><p>姓名:"+that[0].tu_name+"</p><p>登录名:"+that[0].tu_loname+"</p><p>电话:"+that[0].tu_tel+"</p><p>辅导方向:"+that[1].gd_name+"</p></div><div class='ds_bottom'><button>查看更多</button></div></div>";
		});
		$("#each_teac").html(teac_html);
	}

    //表单验证
    $(".add_teacbox>div>p>input").blur(function(){
        var input_name= $(this).attr("name");
        var input_data=$(this).val();
        var input_html;
        var judge;
        if(!input_data){
            input_html=" 必填字段!"
        }else{
        switch (input_name){
            case 'teac_num':
                judge=/^\d{5}$/
              break;
            case 'name':
                judge=/^([\u4e00-\u9fa5]+|([a-zA-Z]+\s?)+)$/;
                break;
            case 'danwei':
                judge=/^([\u4e00-\u9fa5]+|([a-zA-Z]+\s?)+)$/;
                break;
            case 'email':
                judge=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
                break;
            
            case 'phone':
                judge=/^([0-9]{11})?$/;
                break;
             case 'zhiwu':
                 judge=/^[\u4e00-\u9fa5]+$/;
                break;
            default:
                console.log("error");
            }

            if(!judge.test(input_data)){
                input_html=" 录入有误!";
            }else{
                input_html="";
            }
        }
        $(this).next().html(input_html);
 })

})
</script>